﻿using System;
using TradeHelp.MaterializedObjectViews;
using TradeHelp.Utilities;

namespace ConsoleDemo.Data
{
    public class Shoe : IEquatable<Shoe>, IViewEquivalent<Shoe>
    {
        public readonly string Name;
        public readonly int ShoeSize;
        public readonly string Brand;

        public Shoe(string name, string brand, int age)
        {
            Invariant.CheckIsNullOrEmpty(name, "name");
            Invariant.CheckIsNullOrEmpty(brand, "brand");
            Name = name;
            ShoeSize = age;
            Brand = brand;
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Shoe);
        }

        public bool Equals(Shoe other)
        {
            if (other == null) return false;
            if (other.GetType() != GetType()) return false;
            return Name == other.Name && Brand == other.Brand;
        }

        public bool IsViewEquivalentTo(Shoe viewData)
        {
            return Name == viewData.Name && Brand == viewData.Brand && ShoeSize == viewData.ShoeSize;
        }

        public override string ToString()
        {
            return String.Format("{0} {1} {2}", Name, Brand, ShoeSize);
        }
    }
}
